<?php
  require_once('db_connection.php');

$csv = array();

if (($handle = fopen("users_data.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      //print_r($data);
      //echo "Test<br>";
      $csv[] = $data;
    }
    fclose($handle);
}

//print_r($csv);

$header = array_shift($csv);
$header = array_map('strtolower',$header);
$header = array_map('spaceToUnderscore',$header);

foreach ($csv as $data)
{
  $mysqlData = array_combine($header, $data);
  print_r($mysqlData);
  insert('users',$mysqlData);
}


  function spaceToUnderscore($str)
  {
    return str_replace(' ','_',$str);
  }


